<template>
  <div class="">
    <h1>这是二级导航</h1>
    <ul class="con">
      <li
        v-for="item in list"
        :key="item.id"
        @click="$router.push('/detail/' + item.id)"
      >
        <img :src="item.pic" alt="" />
        <h5>{{ item.name }}</h5>
      </li>
    </ul>
  </div>
</template>

<script>
import { ref, reactive, toRefs } from "vue";
import { useStore } from "vuex";
import { useRouter, useRoute } from "vue-router";
import { getList } from "../utils/yx";
export default {
  setup(props, ctx) {
    const store = useStore();
    const router = useRouter();
    const route = useRoute();
    const data = reactive({
      list: [],
    });
    const id = route.params.id;
    getList().then((res) => {
      data.list = res.data.filter((item) => item.categoryId == id);
    });
    return { ...toRefs(data) };
  },
};
</script>

<style lang="scss">
.con {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  li {
    width: 48%;
    img {
      width: 100%;
      height: 200px;
    }
  }
}
</style>
